/*******************************************
 * Copyright 2007 Aphrodite Framework for javaME .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * Email : owner@aphroditeme.dev.java.net
 * Contributors:
 *     Kent Elton - initial API and implementation
 *******************************************/

package com.aphrodite.extns.bluetooth;

import javax.bluetooth.DataElement;
import javax.bluetooth.ServiceRecord;

/**
 * Represents a service offered by the device
 * 
 * @author kentelt
 * 
 */
public final class Service {

	public static final int ATTR_PROVIDERNAME = 258;

	public static final int ATTR_SERVICEDESC = 257;

	// public MClient connect() {
	// javax.microedition.io.Connection connection;
	// String s = record.getConnectionURL(0, false);
	// connection = Connector.open(s);
	// return new MClient(connection);
	//
	// throw new RuntimeException(exception.getMessage());
	// }

	public static final int ATTR_SERVICENAME = 256;
	public static final String UNKNOWN = "(Unknown)";
	public String description;
	public Device device;
	public String name;
	public String provider;
	private ServiceRecord record;

	public Service(Device device, ServiceRecord servicerecord) {
		device = device;
		record = servicerecord;
		DataElement dataelement = servicerecord.getAttributeValue(256);
		if (dataelement != null)
			name = (String) dataelement.getValue();
		else
			name = "UNKNOWN";
		dataelement = servicerecord.getAttributeValue(257);
		if (dataelement != null)
			description = (String) dataelement.getValue();
		else
			description = "UNKNOWN";
		dataelement = servicerecord.getAttributeValue(258);
		if (dataelement != null)
			description = (String) dataelement.getValue();
		else
			description = "UNKNOWN";
	}

	public ServiceRecord getServiceRecord() {
		return record;
	}
}
